//
//  SixDiv_ViewController.m
//  International_Hospital
//
//  Created by 喵小仲 on 16/7/6.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "SixDiv_ViewController.h"

//#import "FocusDoctor_ViewController.h"

#import "ArrowView.h"
#import "ButtonView.h"

#import "SixDivSubViewController.h"

@interface SixDiv_ViewController ()<ArrowViewDelegate>

//用户信息
@property (nonatomic, weak) UILabel *userLabel;
//疾病类型
@property (nonatomic, weak) UILabel *diseaseTypeLabel;
//疾病细分
@property (nonatomic, weak) ArrowView *analyseView;
//并发症选择
@property (nonatomic, weak) ArrowView *concurrentView;
//是否确诊
@property (nonatomic, weak) ButtonView *makeSureView;

//是否接受过治疗
@property (nonatomic, weak) ButtonView *cureView;
//治疗方式
@property (nonatomic, weak) ArrowView *cureTypeView;

//匹配医生
@property (nonatomic, weak) UILabel *findDoctorLabel;

@end

@implementation SixDiv_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:235.0/255 green:235.0/255 blue:241.0/255 alpha:1];
    
    if ([self.navigationItem.title isEqualToString:@"公益"])
    {
        NSString *urlString = @"http://202.106.210.115:18080/hyde-pluto-h360/nt/appEntrance.htm";
        
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
        
        UIWebView *webView = [[UIWebView alloc] init];
        
        [self.view addSubview:webView];
        
        webView.frame = self.view.bounds;
        
        [webView loadRequest:request];
        
        return;
    }
    
    [self setupUI];
}

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
}

- (void)setupUI
{
    NSString *userName = @"王二蛋";
    
    UILabel *userLabel = [[UILabel alloc] init];
    userLabel.text = [NSString stringWithFormat:@"用户信息:     %@",userName];
    self.userLabel = userLabel;
    
    UILabel *diseaseTypeLabel = [[UILabel alloc] init];
    diseaseTypeLabel.text = [NSString stringWithFormat:@"疾病类型:     %@疾病",self.navigationItem.title];
    self.diseaseTypeLabel = diseaseTypeLabel;
    
    [self.view addSubview:userLabel];
    [self.view addSubview:diseaseTypeLabel];
    
    ArrowView *analyseView = [[ArrowView alloc] init];
    self.analyseView = analyseView;
    
    ArrowView *concurrentView = [[ArrowView alloc] init];
    self.concurrentView = concurrentView;
    ButtonView *makeSureView = [[ButtonView alloc] init];
    self.makeSureView = makeSureView;
    ButtonView *cureView = [[ButtonView alloc] init];
    self.cureView = cureView;
    ArrowView *cureTypeView = [[ArrowView alloc] init];
    self.cureTypeView = cureTypeView;
    
    [self.view addSubview:analyseView];
    [self.view addSubview:concurrentView];
    [self.view addSubview:makeSureView];
    [self.view addSubview:cureView];
    [self.view addSubview:cureTypeView];
    
    UILabel *findDoctorLabel = [[UILabel alloc] init];
    findDoctorLabel.text = @"为您匹配到: 42位医生";
    self.findDoctorLabel = findDoctorLabel;
    [self.view addSubview:findDoctorLabel];
    
    UIImageView *doctorImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    [self.view addSubview:doctorImage];
    
    UIButton *applyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [applyButton setTitle:@"就医申请" forState:UIControlStateNormal];
    [applyButton setTitleColor:kThemeColor forState:UIControlStateHighlighted];
    [applyButton setBackgroundColor:kThemeColor];
    applyButton.layer.cornerRadius = 5;
    [applyButton addTarget:self action:@selector(didClickApplyButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:applyButton];
    
    [self.userLabel makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.topLayoutGuide).offset(20);
        make.top.offset(64+20);
        make.left.offset(20);
    }];
    
    [self.diseaseTypeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userLabel.bottom).offset(10);
        make.left.equalTo(self.userLabel);
    }];
    
    [self.analyseView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.diseaseTypeLabel.bottom).offset(10);
        make.left.equalTo(self.userLabel);
        make.right.offset(-20);
        make.height.offset(40);
    }];
    
    [self.concurrentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.analyseView.bottom).offset(10);
        make.left.equalTo(self.userLabel);
        make.right.equalTo(self.analyseView);
        make.height.offset(40);
    }];
    
    [self.makeSureView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.concurrentView.bottom).offset(10);
        make.left.equalTo(self.userLabel);
        make.right.equalTo(self.analyseView);
        make.height.offset(40);
    }];
    
    [self.cureView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.makeSureView.bottom).offset(10);
        make.left.equalTo(self.userLabel);
        make.right.equalTo(self.analyseView);
        make.height.offset(40);
    }];
    
    [self.cureTypeView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cureView.bottom).offset(10);
        make.left.equalTo(self.userLabel);
        make.right.equalTo(self.analyseView);
        make.height.offset(40);
    }];
    
    [self.findDoctorLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cureTypeView.bottom).offset(70);
        make.centerX.equalTo(self.view);
    }];
    
    [doctorImage makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.findDoctorLabel.bottom).offset(10);
        make.centerX.equalTo(self.view);
        make.height.offset(100);
        make.width.offset(100);
    }];
    
    [applyButton makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userLabel);
        make.right.equalTo(self.analyseView);
        make.bottom.offset(-20);
        make.height.offset(40);
    }];
    
    self.analyseView.tag = 1;
    self.concurrentView.tag = 2;
    self.cureTypeView.tag = 3;
    
    [self.analyseView setupUIWithPlaceHolder:@"请选择疾病细分"];
    [self.concurrentView setupUIWithPlaceHolder:@"请选择并发症(可多选)"];
    
    [self.makeSureView setupUIWithPlaceHolder:@"是否确诊" yesString:@"已确诊" noString:@"症状疑似"];
    [self.cureView setupUIWithPlaceHolder:@"是否接受过治疗" yesString:@"接受过" noString:@"未接受过"];
    
    [self.cureTypeView setupUIWithPlaceHolder:@"请选择治疗方式"];
    
    self.cureTypeView.hidden = YES;
    
    [self.cureView setCureTypeViewBlock:^{
        if (self.cureView.yesButton.selected)
        {
            self.cureTypeView.hidden = NO;
        }
        else
        {
            self.cureTypeView.hidden = YES;
        }
    }];
    
    self.analyseView.delegate = self;
    self.concurrentView.delegate = self;
    self.cureTypeView.delegate = self;
}

#pragma mark
#pragma mark -- ArrowView代理方法
- (void)didButtonDelegate:(ArrowView *)arrowView
{
    SixDivSubViewController *sixSubVc = [[SixDivSubViewController alloc] init];
    
    sixSubVc.typyNumber = arrowView.tag;
    
    [sixSubVc setStringBlock:^(NSString *string) {
        
        arrowView.textField.text = string;
    }];
    
    if (arrowView.tag == 2)
    {
        NSString *string = arrowView.textField.text;
        if (string.length > 0)
        {
            NSArray *array = [string componentsSeparatedByString:@"、"];
            
            sixSubVc.saveArray = array;
        }
    }
    
    [self.navigationController pushViewController:sixSubVc animated:YES];
}

#pragma mark
#pragma mark -- ApplyButton点击方法
- (void)didClickApplyButton:(UIButton *)button
{
//    FocusDoctor_ViewController *doctorApplyVc = [[FocusDoctor_ViewController alloc] init];
//    
//    doctorApplyVc.navigationItem.title = @"名医通申请";
//    
//    [self.navigationController pushViewController:doctorApplyVc animated:YES];
}

- (void)dealloc
{
//    NSLog(@"sixdivdealloc");
}

@end
